package com.hnucm.cooklife.ui.fragment;

import android.content.Context;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.hnucm.cooklife.R;
import com.hnucm.cooklife.adapter.MeWorkAdapter;
import com.hnucm.cooklife.base.BaseFragment;
import com.hnucm.cooklife.base.utils.LoginUtils;
import com.hnucm.cooklife.bean.db.Work;
import com.hnucm.cooklife.contract.me.Contract;
import com.hnucm.cooklife.presenter.me.MeWorkPresenter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class MeWorkFragment extends BaseFragment<Contract.IMeWorkView, MeWorkPresenter> implements Contract.IMeWorkView {
    private Context mContext;
    private List<Work> mWorkList = new ArrayList<>();
    private MeWorkAdapter mMeWorkAdapter;
    private int userId;

    @BindView(R.id.recom_recycler)
    RecyclerView mRecyclerView;

    @Override
    protected int getContentViewId() {
        return R.layout.me_dish_fragment;
    }

    @Override
    protected void init() {
        mContext = getActivity().getApplicationContext();
        userId = LoginUtils.getLoginId();
        initAdapter();
        mPresenter.loadMyWork(userId);

    }

    private void initAdapter() {
        GridLayoutManager manager = new GridLayoutManager(getContext(), 3);
        mRecyclerView.setLayoutManager(manager);
        mMeWorkAdapter = new MeWorkAdapter(mContext,mWorkList);
        mRecyclerView.setAdapter(mMeWorkAdapter);

    }

    @Override
    protected MeWorkPresenter createPresenter() {
        return new MeWorkPresenter();
    }

    @Override
    public void onLoading() {

    }

    @Override
    public void onLoadingFailed() {

    }

    @Override
    public void onLoadSuccess() {

    }

    @Override
    public void onLoadMyWork(List<Work> workList) {
        mWorkList.clear();
        mWorkList.addAll(workList);
        mMeWorkAdapter.setWorkList(mWorkList);
    }

    @Override
    public void onRefreshMyWork(List<Work> workList) {

    }
}
